local skill = fk.CreateSkill{
    name = "luminous_pearl_skill",
    attached_equip = "luminous_pearl",
}

skill:addEffect("active",{
    prompt = "#hs__zhiheng",
    can_use = function(self, player)
      return player:usedSkillTimes(skill.name, Player.HistoryPhase) == 0
    end,
    target_num = 0,
    min_card_num = 1,
    max_card_num = function(self, player)
      return player.maxHp
    end,
    card_filter = function(self, player, to_select, selected)
      return #selected < player.maxHp and not player:prohibitDiscard(Fk:getCardById(to_select)) and Fk:getCardById(to_select).name ~= "luminous_pearl"
    end,
   on_use = function(self, room, effect)
      local from = effect.from
      room:notifySkillInvoked(from, "luminous_pearl", "drawcard")
      room:throwCard(effect.cards, skill.name, from, from)
      if not from.dead then
        from:drawCards(#effect.cards, skill.name)
      end
    end,
})

skill:addEffect(fk.EventAcquireSkill,{
    can_refresh = function(self, event, target, player, data)
      return target == player and (data.skill == Fk.skills["hs__zhiheng"] or data.skill == Fk.skills["ld__lordsunquan_zhiheng"] or
      data.skill == Fk.skills["wk_heg__zhiheng"]) and table.find(player:getEquipments(Card.SubtypeTreasure), function(cid)
        return Fk:getCardById(cid).name == "luminous_pearl"
      end)
    end,
    on_refresh = function(self, event, target, player, data)
      player.room:handleAddLoseSkills(player, "-luminous_pearl_skill", nil, false, true)
    end,
})

skill:addEffect(fk.EventLoseSkill,{
    can_refresh = function(self, event, target, player, data)
      return target == player and (data.skill == Fk.skills["hs__zhiheng"] or data.skill == Fk.skills["ld__lordsunquan_zhiheng"] or
      data.skill == Fk.skills["wk_heg__zhiheng"]) and table.find(player:getEquipments(Card.SubtypeTreasure), function(cid)
        return Fk:getCardById(cid).name == "luminous_pearl"
      end)
    end,
    on_refresh = function(self, event, target, player, data)
      player.room:handleAddLoseSkills(player, "luminous_pearl_skill", nil, false, true)
    end,
})

Fk:loadTranslationTable{
    ["luminous_pearl_skill"] = "制衡",
    [":luminous_pearl_skill"] = "出牌阶段限一次，你可弃置至多X张牌（X为你的体力上限），然后你摸等量的牌。<font color='grey'><small>此为【制衡（定澜夜明珠）】</small></font>",
}

return skill